import {
  selectExeclList,
  exportExcel
} from '@/api/proceeds.js'

export default {
  data() {
    return {
      priceTotal: 0,
      params: {
        userName: null,
        startTime: '',
        endTime: ''
      },
      userBillDatas: [],
      tableData: [{
        id: 1,
        title: '四年级语文上册第一单元',
        service: '包月',
        price: '200.00',
        number: 15,
        total: '600.00',
        order_sn: '123564521321000032123',
        pay_sn: '15462453112562236',
        pay_time: '2019-12-21  15:20:00'
      }]
    }
  },
  created() {
    this._fetchDatas()
  },
  methods: {
    _fetchDatas() {
      selectExeclList(this.params).then(response => {
        this.userBillDatas = response.result
        this.getSumTotal()
      })
    },
    getSumTotal() {
      this.priceTotal = 0
      this.userBillDatas.forEach(item => {
        for (var i = 0; i < item.children.length; i++) {
          this.priceTotal += Number(item.children[i].sumTotal)
        }
      })
      this.priceTotal = this.priceTotal.toFixed(2)
    },
    _formDialogConfirm() {
      this._fetchDatas()
    },
    exportFile() {
      const queryParams = this.params
      this.$confirm('是否确认导出收益统计?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        const url = process.env.VUE_APP_BASE_API + 'exportMyExcelList?userName=' + queryParams.userName + '&startTime=' + queryParams.startTime + '&endTime=' + queryParams.endTime
        window.open(url)
      })
    }
  }
}
